<html>
<head>
	<title>Link</title>
	<script type="text/javascript" src="../prototype.js" ></script>
	<link type="text/css" rel="stylesheet" href="../themes/office12/style.css" />
<body>
	<form>
	<table class="formTable" width="100%">
		<tr>
			<td class="formTitle" class="langRec" langKey="url">URL</td>
			<td><input type="text" id="Url" name="Url" style="width:300px" /></td>
		</tr>
		<tr>
			<td class="formTitle" class="langRec" langKey="linktarget">Target</td>
			<td>
				<select type="text" id="Target" name="Target">
					<option value=""></option>
					<option value="_blank">New Window (_blank)</option>
					<option value="_top">Top Frame (_top)</option>
					<option value="custom">Custom</option>
				</select>
			</td>
		</tr>
		<tr>
			<td class="formTitle" class="langRec" langKey="linktitle">Title</td>
			<td><input type="text" id="Title" name="Title" style="width:300px"  /></td>
		</tr>
	</table>
	
	<input type="submit" id="SubmitLink" value="Insert Link" class="langRec" langKey="createlink" /> 
	</form>
	

<script type="text/javascript">	

Event.observe(window,'load',init);
Event.observe('SubmitLink','click',submitLink);
Event.observe(document.getElementsByTagName('form')[0],'submit',submitLink);

var ftb = null
var refresh = null;

function init() {
	
	if (window.opener)
		refresh = window.opener.Refresh;
	else
		refresh = window.parent.Refresh;
	
	ftb = refresh.Web.CurrentFreeTextBox;
	if (ftb == null) ftb = refresh.Web.FreeTextBoxList[0];

	// set language 
	refresh.Web.Localization.updateLanguageElements(document, ftb.settings.language);
	
	var link = ftb.getNearest('a');
	var url = '';
	if (link) {
		var url = link.getAttribute('temp_href');
		if (!url) url = link.getAttribute('href');
	}
	
	$('Url').value = (url != '') ? url : 'http://';	
	$('Url').focus();
}
function submitLink(event) {
	Event.stop(event);

	var url = $F('Url');
	var target = $F('Target');
	var title = $F('Title');
	
	ftb.insertLink(url,target,title);
	
	refresh.Web.ModalWindow.hide();
	window.close();
}
</script>
</body>
</html>